<?php
header("Content-type:text/html;charset=UTF-8");

  class login{
    public function index(){
      $data=json_decode($_POST['data'],true);
      $user=M()->select('user','id,tel,username,password,flag','tel='.$data['tel'])[0];
      if(!is_array($user)) echo 'false';
      if($user['password']==$data['password']){
        $_SESSION['id']=$user['id'];
        $_SESSION['username']=$user['username'];
        $_SESSION['flag']=$user['flag'];
        echo 'true';
      }
      else 'false';
    }

    public function reg(){
      $data=json_decode($_POST['data'],true);
      unset($data['pwd']);
      $data['flag']=0;
      M()->insert('user',$data);
    }

    public function logout(){
      session_destroy();
      header('Location:index.php');
    }
  }
 ?>
